package com.example.zhuwenjing

import Student
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class StudentAdapter(private val students: List<Student>) : RecyclerView.Adapter<StudentAdapter.StudentViewHolder>() {

    class StudentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val studentId: TextView = itemView.findViewById(R.id.studentId)
        val studentName: TextView = itemView.findViewById(R.id.studentName)
        val studentSex: TextView = itemView.findViewById(R.id.studentSex)
        val studentClass: TextView = itemView.findViewById(R.id.studentClass)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StudentViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.activity_main, parent, false)
        return StudentViewHolder(view)
    }

    override fun onBindViewHolder(holder: StudentViewHolder, position: Int) {
        val student = students[position]
        holder.studentId.text = student.studentId
        holder.studentName.text = student.name
        holder.studentSex.text = student.studentSex
        holder.studentClass.text = student.studentClass
    }

    override fun getItemCount(): Int {
        return students.size
    }
}